<?php

    session_start();

    require_once 'photo.php';
    require_once 'configu.php';
    require_once 'database.php';

    $hasil = database::query("SELECT Username FROM user WHERE Email = '$_POST[email]'");
	$baris = mysql_fetch_array($hasil);
    if ((mysql_num_rows($hasil) > 0) && ($baris[0] != $_SESSION["username"])){


        echo '<script>';
            echo 'alert("Email yang Anda masukkan telah terdaftar di Foo-Too.")';
        echo '</script>';
        echo '<script>';
            echo 'document.location = "'.$CFG->url.'profile.php?un='.$_SESSION[username].'";';
        echo '</script>';
    }
    else{
        if ($_POST[password] != NULL)
                database::query("UPDATE user SET Password = '". md5($_POST[password])."', Nama = '".$_POST[nama]."', Email = '".$_POST[email]."', HakAksesWall = '".$_POST[hakakses]."', TanggalLahir = '".$_POST[lahir]."' WHERE Username = '".$_SESSION['username']."'");
        else
                database::query("UPDATE user SET Nama = '".$_POST[nama]."', Email = '".$_POST[email]."', HakAksesWall = '".$_POST[hakakses]."', TanggalLahir = '".$_POST[lahir]."' WHERE Username = '".$_SESSION['username']."'");

        header("Location: ".$CFG->url."profile.php?un=".$_SESSION[username]);
    }

?>
